package com.xhh.stu.activity.impl;

import java.util.Calendar;

import com.xhh.stu.activity.Activity;
import com.xhh.stu.cal.Calculate;
import com.xhh.stu.cal.factory.CalculateFactory;

/**
 * 活动-折扣
 * <p>2017年1月4日 下午4:38:30</p>
 * @author lijian
 * @version 1.0
 */
public class ActDiscount implements Activity {

	private double discount;// zhekou

	public ActDiscount(double discount) {
		super();
		this.discount = discount;
	}

	public double getDiscount() {
		return discount;
	}

	public void setDiscount(double discount) {
		this.discount = discount;
	}

	@Override
	public double getMoney(double sourceMoney) {
		if(!validAct(sourceMoney)){
			return sourceMoney;
		}
		if (sourceMoney < 0) {
			return 0;
		}
		Calculate cal = CalculateFactory.getCalCulateInstance("*");
		return cal.calculate(sourceMoney, discount);
	}

	protected boolean validAct(double sourceMoney) {
		int hour=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
		if(hour>=20){
			return true;
		}
		System.out.println("早于晚8点,使用优惠码失败");
		return false;
	}

}
